<template>
	<view class="app">
		<view class="" style="text-align: center;align-items: center;font-size: 32rpx;font-weight: 700;margin-top: 100rpx;">购买科目:{{ subjectInfo.subjectName }}</view>
		<view class="price-box">
			<text>支付金额</text>
			<text class="price">{{ subjectInfo.payMoney }}</text>
			<!-- {{subjectInfo.money}} -->
		</view>

		<view class="pay-type-list">
			<view class="type-item b-b" @click="changePayType(1)">
				<view style="margin-right: 20rpx;"><uv-icon name="weixin-circle-fill" color="#07c160" size="40"></uv-icon></view>
				<view class="con">
					<text class="tit">微信支付</text>
					<text>推荐使用微信支付</text>
				</view>
				<label class="radio">
					<radio value="" color=" ##07c160" :checked='payType == 1' />
					</radio>
				</label>
			</view>
			<!-- <view class="type-item b-b" @click="changePayType(2)">
				<text class="icon yticon icon-alipay"></text>
				<view class="con">
					<text class="tit">支付宝支付</text>
				</view>
				<label class="radio">
					<radio value="" color=" #ff633d" :checked='payType == 2' />
					</radio>
				</label>
			</view>
			<view class="type-item" @click="changePayType(3)">
				<text class="icon yticon icon-erjiye-yucunkuan"></text>
				<view class="con">
					<text class="tit">预存款支付</text>
					<text>可用余额 ¥198.5</text>
				</view>
				<label class="radio">
					<radio value="" color=" #ff633d" :checked='payType == 3' />
					</radio>
				</label>
			</view> -->
		</view>

		<text class="mix-btn" @click="confirm">确认支付</text>
	</view>
</template>

<script>
import { partnerAppletsWechatOrderPay, searchPlugsPracticeSubjectById } from '../../utils/api.js';
export default {
	data() {
		return {
			payType: 1,
			orderInfo: {},
			dataId: '',
			subjectInfo: {},
			radiolist: [
				{
					name: '一个月'
				},
				{
					name: '两个月'
				},
				{
					name: '三个月'
				},
				{
					name: '六个月'
				},
				{
					name: '一年'
				},
				{
					name: '永久'
				}
			],
			// uv-radio-group的v-model绑定的值如果设置为某个radio的name，就会被默认选中
			radiovalue: '一个月',
			info: {}
		};
	},
	computed: {},
	onLoad(options) {
		this.dataId = options.dataId;
		this.info = JSON.parse(decodeURIComponent(options.info));
		console.log(this.info, 668);
		this.getsubject();
	},

	methods: {
		getsubject() {
			let data = {
				id: this.dataId
			};
			searchPlugsPracticeSubjectById(data).then(res => {
				if (res.code == 200) {
					this.subjectInfo = res.body;
				}
			});
		},
		//选择支付方式
		changePayType(type) {
			this.payType = type;
		},
		//确认支付
		confirm() {
			let postData = {
				businessId: 0,
				client: '小程序',
				dataId: this.dataId,
				extParm: '',
				orderId: this.info.id,
				orderNo: this.info.orderNo,
				payMoney: this.info.payMoney,
				openId: uni.getStorageSync('__ddminiUserOpenid'),
				payType: 5,
				payWay: 1,
				statisticalStatus: 0
			};
			uni.showLoading({
				title: '支付准备中',
				mask: true
			});
			partnerAppletsWechatOrderPay(postData).then(res=>{
				if(res.code==200){
					let payList=res.body
					let data = res.body;
					var RSA = require('@/utils/wxapp_rsa.js')
					let paySign =
						`${data.appid}\n${data.timestamp}\n${data.noncestr}\nprepay_id=${data.prepay_id}\n`
					// 私钥、商户API证书下载后，私钥 apiclient_key.pem 的内容
					let sikey = `-----BEGIN PRIVATE KEY-----
								MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCkKmpbnA4QnZmD
								OVLPPORVj6YNLW+kdc17raHgMng5FXVZ3D6ZxthYHgnJUMSGD82BdqVmOwOvkhwt
								hyCl8gpEi5JOr/88UMlSEwrwQWhKFQFA4SpMW489H+yuQkcUKKHZYQgOGgEoFN8r
								WvqYfhBgixxcoDlzcp4VKzCrM6yibD+BkVBcjRdrWFQhloQyR/Dc+HDAZsQYXlJi
								moUGeYq/BDircT8Vfs8wB3fTx7FoBqfbvkposv+VjjijEAhCR6VRaV7MKPTR4nof
								fo7gHcTg6CGlQaepfwOF4rDmZPFVQXIgphAF17OGUTbw45jpAplWLzh3XYdNvawU
								EZz5MPmzAgMBAAECggEAPTIKf6fGnm8BQKdntRTv0O1Bavwa9+Vp+caZ5ycpJa5Y
								Fm1BcLVtBDv+TesrtwXBB5egxGEPWK1Qj7AlfXaiWTbmDSsSK/u5cDzlAPaA18zI
								sNS+ncQruw9hfPv73wnee1fuVsNe1wAgyNqbO6kSlcqFggnAIMcDIsT82XTjz4+N
								of6sJxQfCwSOR3WKV4r+9F4KXPgre+0wm5aNSQhW1KfV1r918DtHjcDxtvOZn7PB
								GFj/xx3UacZdDOfauqZSMf4ZghCHBCBH/LOVmk3hqEokHHdzP36dm6/CkVoK+sbF
								FYCNlD/t1FUShXbEh+iHnSPbA51Vo5f1+OPKlW99AQKBgQDSJFcWLXuW8DIyz+UN
								5ZL++nFkSWyAShACeOC81fk6wEiatmbmAa0Qs6OcAJuYDeRwt47FX9fsNvm9hud8
								BueYNPmmC0mhO1PSRWQCKDghY+F0/nSV8QB44pR5o7m2yV+B/Pyg12qbBOTg3NLY
								yKYpaxwcDFWEEmRLusAZCLizcwKBgQDH/Zf4W58yUTzK/l3iY4luYZBDMjA5/yFv
								kndQxqsGpzS6KQtOCS5RLhC+1176h8lNy7NdNqca6x15QJ2UhqUOeFVcqbatjaL2
								bv4gro4j2nVOgKmR03fto7s3BKtPHlFPON//R28bWmPm+ap/S/aWS6doNQpOCqW1
								mLKI5LuQwQKBgGbbXrz+OjYhD5ELbSQmMJMZZpMd1TveBIQRQn9rhHgbUe5YRXlj
								bKB2LSjYq0/7zMrXLcyyIu/94LPB6mAsyQMZOvDpKXr/nQGY8WCU6xR83Qf03H/f
								3MlOrjnzx50OZ+8qM0VO62FBPf5KV/HAFITFZpbb+qeQkQL4P7qBKFa9AoGBAKal
								aAbpweQZ0YCNKQpGSvSRk7aKkakiMWhZMdc7VLP8jHE7VlI2UEQREJ8Vs+0rTNDo
								lpNrwR8rH6oz75sd/1fpaagHO1OvHEYhAt2U1piFpw49JA+BmQOKVaxo1Z7d8n8D
								M5PyoGC4l1qWXD4qvFVMwTiSSf3x3VdO4CY2Ax2BAoGATYQfX/vxk6v7gVr4fBQU
								jCd25kxrhQ5GZ1tvL8HND/pz3o1qu5stGAhoM7t2+w6/OxwDCBluKwYx9fcaP1tI
								vA9ebRwGmUQTojjPwQMNfbuQdD1xIq+C6fKg0cSCvRfwDQxXTsjJgpE6Qhs9LygL
								E7Tysgyd8jjH5lEj8r3qCSU=-----END PRIVATE KEY-----`
					
						// 加签
						var sign_rsa = new RSA.RSAKey();
						sign_rsa = RSA.KEYUTIL.getKey(sikey);
						var hashAlg = 'sha256';
						var hSig = sign_rsa.signString(paySign, hashAlg);
						hSig = RSA.hex2b64(hSig); // hex 转 b64
						uni.hideLoading();
					wx.requestPayment({
						appId: payList.appid,
						nonceStr: payList.noncestr,
						package: payList.package,
						signType: 'MD5',
						timeStamp: payList.timestamp,
						paySign: hSig,
						success: function(res) {
							uni.hideLoading();
							uni.showToast({
								title: '微信支付成功'
							});
							setTimeout(function() {
								uni.navigateBack();
							}, 600);
						},
						fail: function(err) {
							uni.hideLoading();
							uni.showModal({
								title: '支付失败',
								content: '订单支付失败，请重新进行支付。如对订单金额有疑问请联系客服人员',
								showCancel: false
							});
							return;
						}
					});
				}
			});
			// uni.redirectTo({
			// 	url: '/pages/money/paySuccess'
			// })
		}
	}
};
</script>

<style lang="scss">
.app {
	width: 100%;
}

.price-box {
	background-color: #fff;
	height: 14 0rpx;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	font-size: 28rpx;
	color: #909399;

	.price {
		font-size: 50rpx;
		color: red;
		margin-top: 12rpx;
		&:before {
			content: '￥';
			font-size: 40rpx;
		}
	}
}

.pay-type-list {
	margin-top: 20rpx;
	background-color: #fff;
	padding-left: 60rpx;

	.type-item {
		height: 120rpx;
		padding: 20rpx 0;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding-right: 60rpx;
		font-size: 30rpx;
		position: relative;
	}

	.icon {
		width: 100rpx;
		font-size: 52rpx;
	}
	.icon-erjiye-yucunkuan {
		color: #fe8e2e;
	}
	.icon-weixinzhifu {
		color: #36cb59;
	}
	.icon-alipay {
		color: #01aaef;
	}
	.tit {
		font-size: 26rpx;
		color: #01aaef;
		margin-bottom: 4rpx;
	}
	.con {
		flex: 1;
		display: flex;
		flex-direction: column;
		font-size: 26rpx;
		color: $uni-text-color;
	}
}
.mix-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 630rpx;
	height: 80rpx;
	margin: 80rpx auto 30rpx;
	font-size: 26rpx;
	color: #fff;
	background-color: #01aaef;
	border-radius: 10rpx;
	box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
}
</style>
